package com.wx.mythread.thread;

public class StaticMethodSynchronize implements Runnable {
    private static StaticMethodSynchronize instance1 = new StaticMethodSynchronize();
    private static StaticMethodSynchronize instance2 = new StaticMethodSynchronize();

    @Override
    public void run() {
        method();
    }

    public void method(){
        synchronized (StaticMethodSynchronize.class) {
            System.out.println("我是类锁静态方法，我叫" + Thread.currentThread().getName() + "开始执行");
            try {
                Thread.sleep(3000);
            } catch (InterruptedException e) {
                e.printStackTrace();
            }
            System.out.println(Thread.currentThread().getName() + "执行结束");
        }
    }

    public static void main(String[] args) {
        Thread thread1 = new Thread(instance1);
        Thread thread2 = new Thread(instance2);
        thread1.start();
        thread2.start();
        while (thread1.isAlive() || thread2.isAlive()) {

        }
        System.out.println("game over");

    }
}
